package com.chap1.waitandnotify;

import com.chap1.tools.SleepTools;

/**
 * Created by IntelliJ IDEA.
 * User: bj910
 * Date:2023-03-28
 * Time: 5:13
 * To change this template use File | Settings | File Templates.
 */
public class TestWN {
    private static Express express = new Express(0,"WUHAN");

    private static class CheckKm extends Thread{
        @Override
        public void run() {
            express.waitKm();
        }
    }

    private static class CheckSite extends Thread{
        @Override
        public void run() {
            express.waitSite();
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 2; i++) {
            new CheckSite().start();
        }

        for (int i = 0; i < 2; i++) {
            new CheckKm().start();
        }

        SleepTools.ms(500);

        for (int i = 0; i < 5; i++) {
            synchronized (express){
                express.change();
                express.notifyAll();//唤醒其他线程，退出同步块，释放锁
            }
            SleepTools.ms(500);
        }
    }
}
